﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;

namespace PineLake.Drmwe.Encrypts.MD5
{
    /// <summary>
    /// MD5加密算法
    /// </summary>
    public class MD5Hash : IMD5
    {
        /// <summary>
        /// MD5加密
        /// </summary>
        /// <param name="EncryptStr">加密字符串</param>
        /// <returns></returns>
        /// 
        public string Encrypt(string EncryptStr)
        {
            try
            {
                byte[] byteArray = Encoding.UTF8.GetBytes(EncryptStr);
                using (HashAlgorithm hashAlgorithm = new MD5CryptoServiceProvider())
                {
                    byteArray = hashAlgorithm.ComputeHash(byteArray);
                    StringBuilder stringBuilder = new();
                    foreach (byte item in byteArray)
                    {
                        stringBuilder.AppendFormat("{0:x2}", item);
                    }
                    hashAlgorithm.Clear();
                    return stringBuilder.ToString();
                }
            }
            catch
            {
                return "403";

            }
        }
    }
}
